;
(function() {
  'use strict';
  angular.module('services.dataQualityMng')
    .service('alarmStatisticsforBPService', alarmStatisticsforBPService);

  function alarmStatisticsforBPService($filter,Restangular) {
    return {
      getName: getName,
      initChart: initChart,
      alarmQuery:alarmQuery,
      fmtSendData: fmtSendData,
      fmtDateTitle: fmtDateTitle,
      getFormatterFn: getFormatterFn
    };

    function alarmQuery(params,callback) {
      Restangular.all('sas/dataManager/dataQuality/dataMonitor/all/query').post(params).then(callback);
    }

    function getFormatterFn(str) {
      return function(params) {
        var name = params.name;
        var seriesName = params.seriesName;
        var value = params.value;
        return seriesName + ' </br>' + name + ':' + value + str;
      };
    }

    function getName(send) {
      var sendName = {
        moduleName: '',
        legendName: ''
      };
      if (send.module === 1) {
        sendName.moduleName = '完整性';
        sendName.legendName = '缺失数据量';
      } else if (send.module === 2) {
        sendName.moduleName = '准确性';
        sendName.legendName = '错误数据量';
      } else {
        sendName.moduleName = '时效性';
        sendName.legendName = '延迟数据量';
      }
      return sendName;
    }

    function fmtSendData(sendData) {
      var send = {
        time: '',
        module: ''
      };
      send.time = $filter('date')(sendData.date, 'yyyy-MM-dd');
      send.module = sendData.module.toString();
      return send;
    };

    function fmtDateTitle(send) {
      var timeTitle = '';
      var year = send.time.substring(0, 4) + '年';
      var month = send.time.substring(5, 7) + '月';
      var day = send.time.substring(8, 10) + '日';
      timeTitle = year + month + day + '';
      return timeTitle;
    };

    //初始化图表（柱状图）
    function initChart(xAxisData, seriesData, title, legendName) {
      return {
        title: {
          text: title,
          x: 'center'
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          data: [legendName],
          x: 'right',
          y: 'center',
          orient: 'vertical'
        },
        xAxis: [{
          type: 'category',
          boundaryGap: true,
          data: xAxisData,
          axisLabel: {
            rotate: 45,
          },
          splitLine: {
            show: false
          }
        }],
        yAxis: [{
          name: '单位(笔)',
          type: 'value',
          axisLabel: {
            formatter: '{value}'
          }
        }],
        series: [{
          name: legendName,
          type: 'bar',
          data: seriesData
        }],
        grid: {
          x: '104',
          x2: '128'
        }
      };
    };
  }
})();